<%@page import="java.net.URLEncoder"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
//假设争取的用户名和密码是admin开头和123
 request.setCharacterEncoding("utf-8");
 String u=request.getParameter("userName");
 String p=request.getParameter("userPass");
 if(u.startsWith("admin")&&"123".equals(p)){
	 //到cookie
	 Cookie c=new Cookie("myuser",u);
	 //设置cookie能活多久
	 c.setMaxAge(86400*7);
	 c.setPath("/");//???
	 response.addCookie(c);
	 
	 session.setAttribute("USER_LOGIN", u);
	 //跳转到welcome.jsp
	//转发
	
	request.getRequestDispatcher("welcome.jsp").forward(request, response);
	return;
 }else{
	// out.print("错误的用户名或者密码!");
	//重定向
	//out.println("<script>alert('错误的用户名或者密码!');</script>");
	response.sendRedirect("fail.jsp");
	//response.sendRedirect("fail.jsp?userName="+URLEncoder.encode(u,"utf-8"));
 }
%>
</body>
</html>